unit Help;

interface

uses Windows;

{ Opens the Crispy Plotter HTML help with the specified topic.
  If no topic is specified then the title page of the HTML help is shown.
  @param Topic Topic to be displayed
  @param(Handle Handle of a window. If a handle is specified then the HTML
    help will be closed if the window with the specified handle is closed.
    If no handle is specified then the HTML help will be closed when the
    application closes.) }
procedure ShowHTMLHelp(Topic: string = ''; Handle: THandle = 0);
{ Returns the file path to the HTML help file that is used for the language
  currently active. If there exists no HTML help for the current language
  then the file path to the English HTML help is returned.
  @return File path to the HTML help file for the current language }
function GetHelpPath: string;

implementation

uses Forms, ResConst, Languages, SysUtils;

function GetHelpPath: string;
begin
  Result := Dir_Prog + Dir_Manual + Format(File_HelpFile, [Language.Language]);
  if (not FileExists(Result)) then
  begin
    Result := Dir_Prog + Dir_Manual + Format(File_HelpFile, ['en']);
    if (not FileExists(Result)) then
      Result := '';
  end;
end;

procedure ShowHTMLHelp(Topic: string; Handle: THandle);
var
  HelpFile: string;
begin
  HelpFile := GetHelpPath;
  if HelpFile <> '' then
  begin
    if Handle = 0 then
      Handle := Application.Handle;
    if (Topic = '') then
      HtmlHelp(Handle, PChar(HelpFile), HH_DISPLAY_TOC, 0)
    else
      HtmlHelp(
        Handle,
        PChar(Format('%s::/%s.html', [HelpFile, Topic])),
        HH_DISPLAY_TOPIC,
        0);
  end;
end;

end.
